package com.sz.sidi.oa.intro;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import com.sz.sidi.oa.action.StatrAction;
import com.sz.sidi.oa.ui.login.ContributionPool;

import util.ReadPropertyUtil;
import util.Session;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

    private IWorkbenchAction introAction;
    private StatusLineContributionItem  longitude; 
    private StatusLineContributionItem  ipaddress; 
    private StatrAction statrAction;
    
	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
		super(configurer);
	}

	protected void makeActions(IWorkbenchWindow window) {
		introAction = ActionFactory.INTRO.create(window);
		register(introAction);
		statrAction = new StatrAction(window);
	}

	protected void fillMenuBar(IMenuManager menuBar) {
		
		MenuManager helpMenu = new MenuManager("file", IWorkbenchActionConstants.M_HELP);
		menuBar.add(helpMenu);
		// Help
		helpMenu.add(introAction);
		
		longitude = new StatusLineContributionItem("longitude",40);
		longitude.setText("当前用户："+Session.getUserinfo().getFusername());
		longitude.setVisible(true);
		ContributionPool.getInstance().setContrbution("longitude", longitude);
		
		String hostname = ReadPropertyUtil.getValueByFiledName(Platform
				.getInstallLocation().getURL().getPath()+"/config/remoting.properties", "remotehost", true);
		
		ipaddress = new StatusLineContributionItem("ipaddress",40);
		ipaddress.setText(hostname == null?"":"服务器IP："+ hostname);
		ipaddress.setVisible(true);
		ContributionPool.getInstance().setContrbution("ipaddress", ipaddress);
	}
	@Override
	protected void fillStatusLine(IStatusLineManager statusLine) {
		 super.fillStatusLine(statusLine); 
		 statusLine.getProgressMonitor();
		 statusLine.add(longitude);
		 statusLine.add(ipaddress);
		 
	}
	@Override
	protected void fillCoolBar(ICoolBarManager coolBar) {
		  IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle());
		  coolBar.add(new ToolBarContributionItem(toolbar, "main")); //$NON-NLS-1$
          toolbar.add(statrAction);
	}
}
